import { getAuthCode, login } from '@/services/User';
import { Button, Form, Input } from 'antd-mobile';
import React from 'react'
import { history } from 'umi';

export default function Login() {
    const [form]=Form.useForm()
  const getCode =async (data:any)=>{
    
    const res= await getAuthCode(data);
    form.resetFields(['authCode'])
    form.setFieldValue('authCode',res)
  
  }
  const onFinish=async(data:any)=>{

    const res = await login(data)
    localStorage.token=res
    console.log(res);
    
  }
  
    
    return (
<Form
    form={form}
    onFinish={onFinish}>
      <Form.Item
      label="账号"
      name='phone'>
        <Input placeholder='账号'/>
      </Form.Item>

      <Form.Item
      label="密码"
      name='authCode'>
        <Input placeholder='密码'/>
      </Form.Item>
      <Button onClick={()=>{getCode(form.getFieldValue('phone'))}}>获取验证码</Button>
      <Button type='submit'>22222222222222222222222222222222</Button>
    </Form>
    );
  }